1 Games Programming with Java and Java 3 D

نویسنده

  • Andrew Davison
چکیده

This article looks at the advantages and disadvantages of using Java and Java 3D for games programming. It assumes the reader is familiar with Java, but presents short overviews of gaming, the low-level APIs OpenGL and DirectX, and Java 3D. No programming examples are included here, although links to online code are supplied. 1. Background to Gaming Giving a definition for ‘computer game’ is problematic, due to the wide range of game types. For example, the ArcadePod site (http://www.arcadePod.com) divides its hundreds of Java games into more than ten categories: 3D games, multiplayer, action, classic, indoor sports, board, outdoor sports, card, mind, casino, educational, and the useful ‘miscellaneous’ catch-all. This makes it difficult to pin down the typical content of a game, and highlights the range of design and programming skills required to create one. Another problem with giving a definition is that game platforms vary enormously, including PCs, dedicated game consoles (e.g. the Sony PlayStation 2), arcade machines, web-based games, hand-held consoles (e.g. the Nintendo Gameboy), interactive TV, set-top boxes (as supplied by some cable networks), cellular phones, and PDAs. 1.1. Revenue PCs and game consoles account for almost all the income from games – about 1/3 from PCs (dominated by Windows), and most of the rest from three games consoles (Sony’s PlayStation 2, Microsoft’s Xbox, and Nintendo’s GameCube) [Veronis Suhler Media 2000]. In October 2002, consulting firm Strategy Analytics (http://www.strategyAnalytics.com) predicted game console shipments to top 41.9 million units in 2002, an increase of 84% over the 2001 level. The PlayStation 2 is expected to account for 63% of sales, followed by the GameCube with 21% and the Xbox with 16%. These numbers highlight the domination of the PlayStation 2 which has accounted for 72% of global cumulative shipments, compared to 16% for the GameCube and 12% for the Xbox. NPDFunworld (http://www.npdfunworld.com/) reported that console game sales in 2002 rose by about 20% over the record US$9.4 billion in 2001. Individual game sales are also increasing: Grand Theft Auto: Vice City from Take Two Interactive sold Games Programming with Java and Java 3D 2 an estimated 3 million copies in its first month of release. This game is likely to become the best selling title of 2002, and of all time. 1.2. Console Hardware Since consoles are so central to gaming, it is interesting to consider their capabilities. The PlayStation 2 processor runs with a clock speed of 294 MHz, has 32Mb of RAM, and a separate graphics chip that can render about 66 million polygons per second. The small amount of RAM is an important constraint upon games wishing to use Java. The introduction of the Xbox changed the game rules (so to speak), with its Pentium III, 64Mb RAM, a 8Gb hard disk, and the ability to render 150-200 million polygons per second. Sony and Microsoft have recently released network adapters for their consoles, highlighting the growing importance of multiplayer games. Future console designs (e.g. the PlayStation 3 and Xbox 2) will bring PCs and consoles even closer, and further emphasize online gaming. The PlayStation 3 (slated to appear at the end of 2004) may use a 3GHz processor, 512Mb RAM, a 120Gb hard disk, and render 2 billion polygons per second. The Xbox 2 (due at the end of 2006) may employ a Pentium 4, a clock speed of 1GHz, 1Gb RAM, a 160Gb hard disk, and render 2-3 billion polygons per second. 1.3. High and Low Profile Games Marner distinguishes between high profile and low profile games [Marner 2002]. A high profile game is endowed with massive development costs (perhaps US$5 million or more), a generous advertising budget, a large development staff, and a very visible presence for game retailers and magazines. To recoup the enormous upfront expenses, high profile games tend to utilise cutting-edge graphics (which require high hardware performance), and tie-ins with other media such as movies or books. A low profile game is aimed at a smaller market, and may be limited to a single platform, or user community. It may have been developed by a single person (or small group), and be advertised in specialized newsgroups and mailing lists, leading to a substantial reduction in costs. Low profile games may have less ‘polish’, use less state-of the-art graphics, and place more emphasis on game design and characterization. 2. Java for Games In this section, we identify reasons for using Java for games programming, and look at some of the popular arguments against it. We focus on the Java language and its standard libraries (i.e. those found in J2SE 1.4); Java 3D will be considered in later sections. 2.1. Why use Java for Games? Games Programming with Java and Java 3D 3 The advantages of programming with Java are well known: object orientation, crossplatform support, code reuse, ease of development, the availability of tools, reliability and stability, good documentation, continuing support from Sun Microsystems, low development costs, the ability to use legacy code (e.g. C, C++), and increased programmer productivity. The portability of Java is sometimes overstated – games in particular often require some ‘tweaking’ to improve their performance on different OSes/machines, such as in the scheduling of threads, data structure and/or algorithm design, or the choice of GUI components. Also, if legacy code written in a different language is utilised then portability is frequently compromised. Productivity is an important advantage, although hard to quantify. An old study from 1998 suggested that software written in pure Java instead of C++ results in a 25% overall time/cost saving, corresponding to an overall productivity increase of 30% (the increase for the code phase alone is 65%) [Quinn and Christiansen 1998]. It is likely that these figures are greater today since the capabilities of the J2SE have improved (e.g. the libraries are larger, tool speed is better). 2.2. Ways of Using Java in Games There are several approaches to writing games with Java: • Applets. Usually the applet is a client for a multiplayer game, and communicates back to its home host where the game server is located. A drawback of applets is their security features, which need to be adjusted by the user before an applet can save files or communicate with different hosts. • Pure Java applications. The meaning of ‘pure’ is somewhat vague since seemingly pure libraries, such as Java 3D, utilise code outside of Java, hidden from the programmer. • Dirty Java applications. Dirty Java programs use a mix of Java and other languages (typically C or C++) by employing JNI, network links, or the Java Communications API [Kreimeier 1999]. This opens up Java to code which may be better optimized for the underlying hardware/OS, but affects portability. • Java as a scripting engine. This is a variant of the dirty Java idea, where the majority of the application is implemented in another language. For example, C++ may be used to write the graphics rendering engine, image loaders, and the user interface for joysticks. Java is utilised for tasks that are hardware independent and/or less performance-oriented, such as user input validation and the game logic. 2.3. Misconceptions There are several misconceptions about Java and gaming: • No one writes serious games in Java. This rests on the definition of ‘serious’, which normally means commercial, high profile games. Of course, there are thousands of low profile, freeware/shareware Java games out on the Web. • Java is too big/slow for games programming, especially when compared to C or C++; Games Programming with Java and Java 3D 4 • Sun Microsystems is not really interested in making Java suitable for the games industry. We address each of these points in the following subsections. 2.3.1. Commercial Games Java is nowhere near as popular a gaming language as C or C++, but it is being used, and in games which have become bestseller. Commercial Java games are mostly CD-based applications, and use dirty Java (often Java and C++). Tom Clancy's Politika (1997) from Red Storm Entertainment (http://www.redstorm.com/) was written in almost pure Java. Tom Clancy’s Rainbow Six (1999) started out by mixing C++ and Java, but they dropped the Java when the code grew too complex [Upton 2000]. Both Shadow Watch (2000) and Tom Clancy’s ruthless.com (1998) were written in Java mixed with C/C++. Roboforge (2001) by Liquid Edge Games (http://www.roboforge.com) was coded in Java and Java 3D; it was given an "Excellent 87%” by PC Gamer Magazine in December 2001. IL-2 Sturmovik (2001) by Maddox Games (http://www.il2sturmovik.com/) used dirty Java, with part of the game engine written in Java but all the graphics in C++. At QuakeCon 2001, Fullsail Real World Entertainment showed a Quake clone called Jamid and F1 Grand Prix Demo, both written in Java using Java 3D. However, nothing much has been heard of them lately. Dirty Java was used by Jellyvision (http://www.jellyvision.com/) in their popular Who wants to be a Millionaire (2000) and You don't know Jack (1995) games. They utilised C++ with Java for the game logic, which was also the approach in Majestic (2001) by Electronic Arts (http://www.ea.com/). Java was used as a scripting language in the acclaimed Vampire the Masquerade: Redemption (2000) from Nihilistic software (http://www.nihilistic.com/). The company was very happy with Java, although it only used JDK 1.1 [Huebner 2000]. Star Wars Galaxies from LucasArts (http://www.lucasarts.com/) is being scripted with a ‘slimmed-down’ version of Java. Runescape (http://www.runescape.com) is a massive 3D multiplayer fantasy adventure game. It is probably the largest pay-to-play Java online game, with over 5000 paying members and 1 million free registrations. Clients can use a Java applet to play, or download a Windows-based client application. A telling exception from this list are Java games on consoles. The only examples to date are the Sega Dreamcast games Skies of Arcadia (2000) and Daytona USA (2001), which contained a PersonalJava virtual machine [Patrizio 2000]. However, the Dreamcast is no longer in production. 2.3.2. Freeware/Shareware Games There are many Java games out on the Web, but finding an entertaining game requires a careful search. Games Programming with Java and Java 3D 5 First some history: JDK 1.0 was released early in 1996, JDK 1.1 in early 1997, and Java 2 (JDK 1.2) at the end of 1998. Back then, there was a lot of hype promoting Java as a perfect way of programming networked, graphical programs (i.e. as applets), and this is reflected in the very large number of freeware game applets dating from 1996-1998. Unfortunately, the early versions of Java were very slow, leading to disappointing game play. Also, many programmers ignored the overheads of downloading large code, images, audio, etc. Applet security restrictions and weaknesses in Java’s media APIs (graphics, sounds, etc) were further problems. All of this contributed to a general feeling that Java was a toy language. Recent versions of Java are quite different: speed is much improved, and APIs crucial to gaming, such as graphics and audio, are of a high quality. Also, there has been a move away from the use of applets towards the downloading of client-side applications. Java applications require less configuration, and once downloaded they don’t need to be downloaded again. Java’s backward compatibility allows the applets from 1996-8 to be executed, and they will often run quicker than originally. However, it’s probably best to steer clear of these Java dinosaurs, and look for more modern code. There are many Web sites with Java games. The emphasis of the following list are on applications/applets for playing: • ArcadePod.com, http://www.arcadepod.com/java/ Over 700 Java games, nicely categorized. • Java 4 Fun, http://www.java4fun.com/java.html Similar in style to ArcadePod, and a good set of links to other sites. • Java Game Park, http://javagamepark.com Organized around game categories. • Java Games Central, http://www.mnsi.net/~rkerr/ A personal Web site which lists games with ratings and links. • jars.com, http://www.jars.com This is a general Java site, but contains many games. • Java Shareware, http://www.javashareware.com/ Another general site: look under the categories: applications/games/ and applets/games. Programmers looking for source code should start elsewhere, as detailed below: • FreshMeat.com, http://freshmeat.net/ Freshmeat maintains thousands of applications, most released under open source licenses. The search facilities are excellent, and can be guided by supplying game category terms. The results include rating, vitality, and popularity figures for each piece of software. A recent search for Java games returned over 100 hits. • SourceForge, http://sourceforge.net/search/ SourceForge acts as a repository, and management tool, for software projects, many with source code. A recent search for Java games returned over 250 hits. Games Programming with Java and Java 3D 6 However, many of the projects are at the planning stage, with some inactive for long periods. • Code Beach, http://www.codebeach.com CodeBeach has a searchable subsection for Java games that currently contains nearly 90 example. • Programmers Heaven, http://www.programmersheaven.com/zone13/ It has a ‘Java zone’ containing some games. 2.3.3. Java is too big/slow When people say that Java is too big/slow, they usually mean when compared to C or C++. Earlier version of Java were very slow. Marner presents figures showing JDK 1.0 to be 20 to 40 times slower than C++ [Marner 2002]. Fortunately, successive versions have brought Java much closer to C++: J2SE 1.4 is typically 1.2-1.5 times slower. These numbers depend greatly on the coding style used – Java coded in a straightforward, textbook-style may still be 2.5 to 4 times slower. This shows that Java programmers must be good programmers in order to utilise Java efficiently (but that’s true of any language). Jack Shirazi's Java Performance Tuning website (http://www.javaperformancetuning.com/) is a good source for performance tips, and links to tools and other resources. Recent numerical benchmarks on Linuxes found that compiled C++ and Fortran were at least twice as fast as Java byte code. But the performance was very dependent on the chosen JVM; IBM's implementation exceeded the performance of C++ code compiled with gcc [Ladd 2003]. A detailed comparison of difference versions of Java and other companies’ virtual machines and native code compilers can be found in [Doederlein 2002]. An area of Java that is still slow is its GUI API, Swing. GUI components are created and controlled from Java, with little OS support: this increases their portability and makes them more controllable from within a Java program. The downside is speed since Java imposes an extra layer of processing above the OS. This is one reason why some games applications still utilise the original Abstract Windowing Toolkit (AWT) -it is mostly just simple wrapper methods around OS calls. However, most games do not require complex GUIs: full-screen game play with mouse and keyboard controls are the norm, so GUI speed is less of a factor. Another speed drain is Java’s garbage collector, which is run automatically by the JVM, and may cause an appreciable slowdown in game animation. This is one area where good coding style can alleviate the problem, by the programmer reducing the number of temporary objects created during execution. Knowing which version of Java you are using is important, especially when executing applets. Many browsers, such as Netscape 6 and Microsoft Internet Explorer 6 default to a JVM at version 1.1 unless the user configures things differently. The speed-up in Java is mostly due to improvements in compiler design. The Hotspot technology introduced in J2SE 1.3 enables the run-time system to identify crucial areas of code that are utilised many times, and these are aggressively compiled. Hotspot technology is relatively new, and it’s quite likely that future versions of Java Games Programming with Java and Java 3D 7 will find further speed-ups. The Hotspot technology has the unfortunate side-effect that program execution is often slow at the beginning until the code has been analyzed and compiled. A final point about speed is knowing what to blame when a Java program runs slowly. An increasingly large part of the graphics rendering of a game is handled by hardware or software outside of Java. For example, Java 3D passes all of its rendering down to OpenGL or DirectX which may emulate hardware capabilities, such as bump mapping. Often the performance bottleneck in network games is the network. Dirty Java code passes control to libraries/functions which are quite independent of Java. Java uses a large amount of memory at runtime, for two main reasons: it loads the JVM and associated libraries into memory (about 5-10 MB), and Java objects are stored on the heap rather than the stack [Hutchinson 2000]. Memory requirement is a serious issue when porting Java to consoles. For instance, the PlayStation 2 only has 32MB of RAM. It is being addressed in the Java Game Profile, described below, which uses the Java Micro Edition, so called because its memory needs are more suited to hand-held devices. A longer term solution is to simply wait – the memory specifications for the next generation of consoles are more than sufficient to cope with Java. However, waiting 2-4 years makes poor commercially sense. 2.3.4. Sun Microsystems isn’t interested in Java games The games market isn’t a traditional one for Sun, and it will probably never have the depth of knowledge of a Sony, Sega, or Nintendo. However, the last few years have shown its increasing commitment to gaming. J2SE has strengthened its games support: version 1.4 introduced full-screen imaging and page flipping using hardware. Faster I/O, memory mapping, and support for nonblock sockets are all useful, the latter especially so in client/server multiplayer games. Version 1.3. introduced a timer API that can be employed in animation, and improved graphics and audio support. Recent Java extension libraries, such as Java 3D, the Java Media Framework (JMF), Java Sound, the Java Communications API, Jini, and JAXP (Java’s peer-to-peer API) all offer something to games programmers. At the 2001 Game Developers Conference, Sun announced a collaboration with several other companies, including Sega and Sony, to develop a Java gaming API called the Java Game Profile [JSR 134 2001]. It will be targeted at two markets: highend game devices (using J2ME) and desktop machines (using J2SE). The proposal lists several advantages of Java over other languages: its superior reliability, reduced time-to-market on games, device independence, platform scalability, the prevention of lock-in to a particular platform, and a broader target market. It names several media API that may be useful, including Java 3D, JMF and Java Sound, and suggests the creation of some new ones: APIs for physics modeling, animation, and game marshalling. Companies involved in the project include Math Engine (http://www.mathengine.com/), who developed the Karma rigid body dynamics API, and GameSpy (http://www.gamespy.net/) who offer toolkits that allow players to utilise various multiplayer game servers. The proposal does not say how these extensions will be crammed into a typical game console, which may explain why there hasn’t been much activity in the last year. Games Programming with Java and Java 3D 8 Currently, the Java Game Profile specification is due out in the second quarter of 2003. Part of the initiative was the creation of the JavaGaming.org website (http://www.javagaming.org), which has recently become more active, and offers some good forums on games programming. 2.4. When should Java be used for Games Programming? Java is suited for programming high profile, commercial games, but in conjunction with C or C++ so that legacy code, such as a proprietary game engine, can be utilised. It should also be remembered that well-written Java code is approaching the speeds of C/C++. A serious issue is when Java will be available on consoles. It seems likely that Java will appear on the PlayStation in the near future. Java is more than adequate for low profile games on PCs,, and a quick search through the sites mentioned in section 2.3.2 will confirm its popularity. 3. Graphics APIs for Gaming Java 3D is built on top of lower level graphics libraries: it can either use DirectX or OpenGL. It is useful to understand a little about these APIs before considering Java 3D itself. 3.1. Direct X DirectX is a collection of related gaming modules that provide access to hardware via low-level function available through the Windows OS (http://www.microsoft.com/directx). Its principal aims are to make Windows suitable for game development and to simplify the software interface to the enormous variety of hardware that can be part of a typical PC. DirectX bypasses most of Windows to communicate directly with hardware through HAL (see figure 1). If the required feature is not present then HEL is brought into play to emulate the capability. The graphics API, DirectX Graphics (formerly DirectDraw and Direct3D in v.7.0 and earlier), supports a traditional graphics pipeline, describing all geometry in terms of vertices and pixels. This places quite a burden on the programmer’s shoulders, but the payoff is an API with a multitude of games-related features, Windows Application Direct3D Retained Mode Direct3D Immediate Mode Direct3D Hardware Emulation Layer (HEL) Direct3D Hardware Abstraction Layer (HAL)

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

Games Programming with Java and Java 3D

This article looks at the advantages and disadvantages of using Java and Java 3D for games programming. It assumes the reader is familiar with Java, but presents short overviews of gaming, the low-level APIs OpenGL and DirectX, and Java 3D. No programming examples are included here, although links to online code are supplied. 1. Background to Gaming Giving a definition for ‘computer game’ is pr...

متن کامل

Comparing M3g and Jsr-239 for 3d Games Programming

We compare two graphics APIs for programming 3D games in Java on mobile devices: M3G (Mobile 3D Graphics API for Java, JSR-184) and JSR-239 (a Java binding for OpenGL ES 1.x). We have developed a series of casual games (a puzzle game, a simple FPS, a strategy game, and others) using the versions of M3G and JSR-239 available in Sun's Wireless Toolkit 2.5.1, and use them to compare the APIs in th...

متن کامل

Multivariate Analysis of Morphological Traits of Local Goats in Central Java, Indonesia

The objective of this research was to discriminate four local breeds of goat in Central Java-Indonesia using multivariate analysis. Data from eight morphological traits of four goat breeds, namely Kejobong goat (JG), Etawa Grade goat (EGG), Kacang goat (KG) and Jawarandu goat (RG) originated from Purbalingga, Purworejo, Grobogan and Pemalang regencies, respectively, were used. One hundred and s...

متن کامل

The Myths (and Truths) of Java Games Programming

This paper examines the commonly-expressed criticisms of Java as a games programming language: that's it's too slow, too high-level, prone to memory problems, too hard to install, not available on games consoles, not used in 'real' games, and not even considered a gaming platform by Sun Microsystems. All of these views are incorrect, aside from the console issue.

متن کامل

Cyber Java Monopoly: Game-based approach of collaborative programming language learning

Game-based learning is one of the modern pedagogical approaches beginning to gain attention in education. The intention of adopting games in learning is to offer an additional option for online teaching and to provide students with possibilities to acquire skills and competencies. The teacher’s perspective game-based learning motivates students to become active learners while offering alternati...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 2003